<template>
  <div class="personal">
    <router-link :to="'/edit_profile/' + userinfo.id">
      <div class="profile">
        <img :src="userinfo.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span class="iconfont iconxingbienan"></span>{{ userinfo.nickname }}
          </div>
          <div class="time">{{ userinfo.create_date | dataForm }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell
      title="我的关注"
      desc="关注的用户"
      @click="$router.push({ name: 'myfollow' })"
    />
    <mycell title="我的跟帖" desc="跟帖/回复" />
    <mycell
      title="我的收藏"
      desc="文章/视频"
      @click="$router.push({ name: 'statr' })"
    />
    <mycell title="设置" />
    <mybutton @click="handler">退出</mybutton>
  </div>
</template>

<script>
import mycell from "@/components/mycell.vue";
import mybutton from "@/components/mybutton.vue";
import { getUserInfo } from "@/apis/user.js";
import axios from "@/utils/myaxios.js";
import { dataForm } from "@/utils/myfilter.js";
export default {
  data() {
    return {
      userinfo: {},
    };
  },
  methods: {
    handler() {
      // 点击是删除token
      localStorage.removeItem("token");
      this.$router.push({ path: "/index" });
    },
  },
  components: {
    mycell,
    mybutton,
  },
  // 注册过滤器 由于我们封装的是函数，所以的进行注册
  filters: {
    dataForm,
  },
  async mounted() {
    // 获取到id
    let id = this.$route.params.id;
    let res = await getUserInfo(id);
    // console.log(res); //获取到请求的数据
    this.userinfo = res.data.data;
    // 判定图片如果有这个图片
    if (this.userinfo.head_img) {
      // 就使用基准路基拼接图片 如果有图片就用请求回来的图片
      this.userinfo.head_img = axios.defaults.baseURL + this.userinfo.head_img;
    } else {
      // 否则就使用默认的图片进行路径的拼接
      this.userinfo.head_img =
        axios.defaults.baseURL + "/uploads/image/luban.jpeg";
    }
  },
};
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}

.btn {
  margin: 20px auto;
  background-color: #f00;
}
</style>